package com.gugee.ins.deploy.all;


import com.gugee.ins.common.constant.InsBloggerMsgTypeCodeEnum;
import com.gugee.ins.common.dal.service.dic.InsDicCategoryDao;
import com.gugee.ins.common.dal.service.spider.SpiderSvc;
import com.gugee.ins.common.dal.spider.InsBloggerSpiderClient;
import com.gugee.ins.common.model.mysql.dic.InsDicCategory;
import com.gugee.ins.data.analysis.service.InsAnalysisIncomeService;
import com.gugee.ins.data.blogger.statistics.core.StBloggerActiveFollowerDataService;
import com.gugee.ins.data.common.msg.InsBloggerMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
@Slf4j
public class BloggerControllerTest {

    @Autowired
    @Qualifier("kafkaTemplateInsBlogger")
    private KafkaTemplate<Long, InsBloggerMessage> kafkaTemplateInsBlogger;

    @GetMapping(path = "/beginCollect/{uid}")
    public void beginCollect(@PathVariable long uid) {
        String userName = "philipp.frank.art";
        String picUrl = "https://scontent-sjc3-1.cdninstagram.com/v/t51.2885-19/s150x150/79376590_460356608234321_5602248452051304448_n.jpg?_nc_ht=scontent-sjc3-1.cdninstagram.com&_nc_ohc=yH_w1NlD1ZoAX_Ga1pv&tp=1&oh=088d2513a5fc82ba09a13991fec53a93&oe=60072570";
        InsBloggerMessage insBloggerMessage = new InsBloggerMessage();
        insBloggerMessage.setUid(uid);
        insBloggerMessage.setUserName(userName);
        insBloggerMessage.setPicUrl(StringUtils.isEmpty(picUrl) ? "" : picUrl);
        kafkaTemplateInsBlogger.send("insBlogger_cl_day",insBloggerMessage);
    }

    @Autowired
    InsBloggerSpiderClient insBloggerSpiderClient;
    /**
     * 爬虫接口
     */
    @Autowired
    SpiderSvc spiderSvc;

    @GetMapping(path = "/test/{uid}")
    public void testAroundAdvice(@PathVariable long uid) {
        spiderSvc.getInsBloggerByUid(uid);
    }

    @GetMapping(path = "/sendFollowing/{uid}")
    public void sendFollowing(@PathVariable long uid) {
        InsBloggerMessage insBloggerMessage = new InsBloggerMessage();
        insBloggerMessage.setUid(uid);
        kafkaTemplateInsBlogger.send("insBloggerFollowing_day",insBloggerMessage);
    }

    @GetMapping(path = "/sendInsAnalysisLocation/{uid}")
    public void sendInsAnalysisLocation(@PathVariable long uid) {
        InsBloggerMessage insBloggerMessage = new InsBloggerMessage();
        insBloggerMessage.setUid(uid);
        kafkaTemplateInsBlogger.send("insAnalysisLocation_day",insBloggerMessage);
    }

    @GetMapping(path = "/sendStRealFollower/{uid}")
    public void sendStRealFollower(@PathVariable long uid) {
        InsBloggerMessage insBloggerMessage = new InsBloggerMessage();
        insBloggerMessage.setUid(uid);
        kafkaTemplateInsBlogger.send("mblogger_rf_st_day",insBloggerMessage);
    }

    @Autowired
    StBloggerActiveFollowerDataService stBloggerActiveFollowerDataService;

    @Autowired
    InsAnalysisIncomeService insAnalysisIncomeService;

    @GetMapping(path = "/sendStIncome/{uid}")
    public void sendStIncome(@PathVariable long uid) {
        InsBloggerMessage insBloggerMessage = new InsBloggerMessage();
        insBloggerMessage.setUid(uid);
        insBloggerMessage.setTypeCode(InsBloggerMsgTypeCodeEnum.ST_INCOME.getCode());
        List<InsBloggerMessage> insBloggerMessages = new ArrayList<>();
        insBloggerMessages.add(insBloggerMessage);
        stBloggerActiveFollowerDataService.handler(insBloggerMessages);
    }

    @GetMapping(path = "/sendAnalysisIncome/{uid}")
    public void sendAnalysisIncome(@PathVariable long uid) {
        InsBloggerMessage insBloggerMessage = new InsBloggerMessage();
        insBloggerMessage.setUid(uid);
        insBloggerMessage.setTypeCode(InsBloggerMsgTypeCodeEnum.ST_INCOME.getCode());
        List<InsBloggerMessage> insBloggerMessages = new ArrayList<>();
        insBloggerMessages.add(insBloggerMessage);
        insAnalysisIncomeService.handleAnalysisIncome(insBloggerMessages);
    }

    @Autowired
    InsDicCategoryDao insDicCategoryDao;

    @GetMapping(path = "/badSqlLog")
    public void badSqlLog() {
        InsDicCategory insDicCategory1 = new InsDicCategory();
        insDicCategory1.setId(232323);
        insDicCategory1.setCategory("Zoo");
        insDicCategory1.setOverallCategory("Animals");
        insDicCategoryDao.save(insDicCategory1);
    }

    @GetMapping(path = "/badSqlLogBatch")
    public void badSqlLogBatch() {
        InsDicCategory insDicCategory2 = new InsDicCategory();
        InsDicCategory insDicCategory3 = new InsDicCategory();
        insDicCategory2.setId(2222222);
        insDicCategory2.setCategory("Veterinarian");
        insDicCategory2.setOverallCategory("Animals");
        insDicCategory3.setId(3333333);
        insDicCategory3.setCategory("Pet Sitter");
        insDicCategory3.setOverallCategory("Animals");
        List<InsDicCategory> list = new ArrayList<>(3);
        list.add(insDicCategory2);
        list.add(insDicCategory3);
        insDicCategoryDao.saveOrUpdateBatch(list);
    }
}


